package com.extremeforce.module;

import java.util.ArrayList;
import java.util.HashMap;

import com.extremeforce.R;
import com.extremeforce.adapter.SingleGoodsAdapter;
import com.extremeforce.db.DBMaster;
import com.extremeforce.entity.SalesInformation;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListView;

public class ViewSingleGoodsActivity extends Activity{

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.singlegoodslayout);
		Intent intent = getIntent();
		DBMaster dbMaster = new DBMaster(ViewSingleGoodsActivity.this);
		Cursor cursor = dbMaster.getSingleGoods(intent.getStringExtra("GOODS_ID"));
		
		ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
		
		while(cursor.moveToNext()){
			SalesInformation sif = new SalesInformation();				
			
			sif.setItemId(cursor.getInt(cursor.getColumnIndex("ITEM_ID")));
			sif.setShopName(cursor.getString(cursor.getColumnIndex("SHOP_NAME")));
			sif.setGoodsDiscount(cursor.getDouble(cursor.getColumnIndex("GOODS_DISCOUNT")));
			sif.setStartTime(cursor.getString(cursor.getColumnIndex("START_TIME")));
			sif.setEndTime(cursor.getString(cursor.getColumnIndex("END_TIME")));
			sif.setGoodsName(cursor.getString(cursor.getColumnIndex("GOODS_NAME")));
			sif.setShopId(cursor.getString(cursor.getColumnIndex("SHOP_ID")));
			sif.setGoodsId(cursor.getString(cursor.getColumnIndex("GOODS_ID")));
			
			
			HashMap<String,String> map = new HashMap<String, String>();
			
			map.put("ITEM_ID",String.valueOf(sif.getItemId()));
			map.put("SHOP_NAME",sif.getShopName());
			map.put("GOODS_NAME",sif.getGoodsName());
			map.put("START_TIME",sif.getStartTime());
			map.put("END_TIME",sif.getEndTime());
			map.put("DISCOUNT_NUM",String.valueOf(sif.getGoodsDiscount()));
			map.put("SHOP_ID",sif.getShopId());
			map.put("GOODS_ID",sif.getGoodsId());
			map.put("SALES_ID",cursor.getString(cursor.getColumnIndex("ITEM_ID")));
			map.put("EXEC_TIME",cursor.getString(cursor.getColumnIndex("EXEC_TIME")));
			list.add(map);
		}
		
		dbMaster.close();
		SingleGoodsAdapter sga = new SingleGoodsAdapter(this,list);
		ListView listView = (ListView)findViewById(R.id.singlegoods_infoListView);
		listView.setAdapter(sga);
	}
	
}
